package com.huawei.hwid.f;

import com.huawei.hms.aaid.constant.AaidIdConstant;
import com.huawei.hwid.core.d.b.e;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public final class f {
    public static byte[] a(File file) {
        Throwable th;
        Throwable th2;
        InputStream inputStream = null;
        InputStream bufferedInputStream;
        try {
            MessageDigest instance = MessageDigest.getInstance(AaidIdConstant.SIGNATURE_SHA256);
            bufferedInputStream = new BufferedInputStream(new FileInputStream(file));
            try {
                byte[] bArr = new byte[4096];
                int i = 0;
                while (true) {
                    int read = bufferedInputStream.read(bArr);
                    if (read == -1) {
                        break;
                    }
                    i += read;
                    instance.update(bArr, 0, read);
                }
                if (i > 0) {
                    byte[] digest = instance.digest();
                    c.a(bufferedInputStream);
                    return digest;
                }
                c.a(bufferedInputStream);
                return new byte[0];
            } catch (NoSuchAlgorithmException e) {
                inputStream = bufferedInputStream;
                try {
                    e.d("SHA256", "NoSuchAlgorithmException An exception occurred while computing file 'SHA-256'.", true);
                    c.a(inputStream);
                    return new byte[0];
                } catch (Throwable th3) {
                    th = th3;
                    bufferedInputStream = inputStream;
                    th2 = th;
                    c.a(bufferedInputStream);
                    throw th2;
                }
            } catch (IOException e2) {
                inputStream = bufferedInputStream;
                e.d("SHA256", "IOException An exception occurred while computing file 'SHA-256'.", true);
                c.a(inputStream);
                return new byte[0];
            } catch (Throwable th4) {
                th2 = th4;
                c.a(bufferedInputStream);
                throw th2;
            }
        } catch (NoSuchAlgorithmException e3) {
            e.d("SHA256", "NoSuchAlgorithmException An exception occurred while computing file 'SHA-256'.", true);
            c.a(inputStream);
            return new byte[0];
        } catch (IOException e4) {
            e.d("SHA256", "IOException An exception occurred while computing file 'SHA-256'.", true);
            c.a(inputStream);
            return new byte[0];
        } catch (Throwable th32) {
            th = th32;
            bufferedInputStream = null;
            th2 = th;
            c.a(bufferedInputStream);
            throw th2;
        }
    }
}
